package br.ifpb.edu.asynctaskjson;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import br.ifpb.edu.asynctaskjson.asynctask.LoginAsyncTask;

public class LoginActivity extends Activity implements
		OnClickListener {
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);

		Button connectPostButton = (Button) findViewById(R.id.loginButton);
		connectPostButton.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		
		EditText emailEditText = (EditText) findViewById(R.id.emailEditText);

		EditText passwordEditText = (EditText) findViewById(R.id.passwordEditText);

		JSONObject pessoa = new JSONObject();
		JSONObject folha = new JSONObject();
		
		try {

			folha.put("email", emailEditText.getText());
			folha.put("password", passwordEditText.getText());
			
			pessoa.put("pessoa", folha);
			
			LoginAsyncTask loginAsyncTask = new LoginAsyncTask();			
			loginAsyncTask.execute(pessoa);
			
		} catch (JSONException e) {
			
			Log.e("EzCab", e.getMessage());
		}
	}
}